importPackage(Packages.aurelienribon.tweenengine);
importPackage(Packages.aurelienribon.tweenengine.equations);

var Timeline=Packages.aurelienribon.tweenengine.Timeline;
var Tween=Packages.aurelienribon.tweenengine.Tween;
var Linear=Packages.aurelienribon.tweenengine.equations.Linear.INOUT;

var scheduler=new Object();
scheduler.getSize=function(stage){
	return 1;
}

scheduler.getTimes=function(stage){
	return [0];
}

scheduler.getParameters=function(stage){
	return new Array();
}

scheduler.getMethods=function(stage){
	return ["step1"];
}

scheduler.step1=function(stage){
	
	var count=stage.getMissileCount();
	var xstep=100;
	var zone=count*xstep;	
	var xoffset=(count==1?stage.getTargetPosition().x:Math.min(512-zone/2,stage.getTargetPosition().x));
	
	var upToDown=(Math.random()>0.5);
	
	var createTimeline=function(t){
		var timeline=Timeline.createSequence().beginSequence();
		timeline.pushPause(1)
				.push(Tween.to(t,1,1).target(x0,y1));
		timeline.end();
		
		return timeline;
	}
	
	for(var x=0;x<count;x++){
		
		// prepare path parameters
		var x0=xoffset+x*xstep;
		var y0=(upToDown?600:0);
		var y1=(upToDown?-100:700);

		// create actor
		var actor=stage.createSpecialMissileActor();
		actor.setMissileType((upToDown?1:2));
		actor.setModelPosition(x0,y0);
		
		stage.tweenSpecialMissileActor(actor,createTimeline(actor));
		
		// create virtual actor for prediction
		var virtualActor=stage.createVirtualSpecialMissileActor(actor);
		virtualActor.setPosition(x0,y0);
		stage.tweenVirtualSpecialMissileActor(virtualActor,createTimeline(virtualActor));
		
		upToDown=!upToDown;
	}
	
	
}
